#ifndef NORMALSCREEN_H
#define NORMALSCREEN_H

#include <QLabel>
#include <QTimer>

struct AVCodecContext;
struct SwsContext;
struct AVFrame;

class NormalScreen : public QLabel
{
    Q_OBJECT
public:
    explicit NormalScreen(QWidget *parent = nullptr);
    explicit NormalScreen(int id, QWidget *parent = nullptr);

    int getId();
//    // 设置mouseMove信号触发时机，true是总是触发，false是只有当鼠标按下时触发
//    // 默认是true
//    void setMouseMoveEmitAlways(bool flag);
protected:
    // 鼠标事件
    void mousePressEvent(QMouseEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;
    void mouseReleaseEvent(QMouseEvent* event) override;
    void wheelEvent(QWheelEvent *event) override;

    QPoint convertToReal(const QPointF &inPoint);
    // 键盘事件
    void keyPressEvent(QKeyEvent *event) override;
    void keyReleaseEvent(QKeyEvent *event) override;
signals:
    // 鼠标信号
    void mouseChanged(const Qt::MouseButtons&, bool isPress, const QPoint&);
    // 键盘信号
    void keyChanged(int key, bool isPress);
    void wheelChanged(int delta);
public slots:
    void setPixmap(const QPixmap &pixmap);
    void putFramebuffer(const QByteArray &data);
    // 设置远端屏幕大小
    void setScreenSize(int width, int height, int codecId);
    void on_timeout();
private:
    void initCodec(int width, int height, int codecId);
    void freeCodec();
private:
    int m_screenWidth;
    int m_screenHeight;
    qreal oldx;
    qreal oldy;
    int m_codec_id;
    int m_id;
    AVCodecContext *m_c;
    SwsContext *m_sws;
    AVFrame *m_argbFrame;
    bool m_timeout;
    QTimer m_timer;
};

#endif // NORMALSCREEN_H
